package cn.peifu.hrm.exception;

import cn.peifu.hrm.util.AjaxResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
//@ControllerAdvice  申明当前类在controller之前或之后执行
public class CommonExceptionHandler {

    /**
     * 处理全局的 GlobalException
     * @param e
     * @return
     */
    @ExceptionHandler(value = GlobalException.class)
    public AjaxResult handlerGlobalException(GlobalException e){
        return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public AjaxResult handlerGlobalException(Exception e){
        e.printStackTrace();
        return AjaxResult.me().setSuccess(false).setMessage("系统错误，我们正在殴打程序员！！");
    }
}